package com.iris.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class AioServer {
    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
        AsynchronousServerSocketChannel serverChannel = AsynchronousServerSocketChannel.open();
        serverChannel.bind(new InetSocketAddress(8888));
        while(true){
            System.out.println("1");
            Future<AsynchronousSocketChannel> future = serverChannel.accept();
            System.out.println("2");
            AsynchronousSocketChannel socketChannel = future.get();
            System.out.println("3");
            socketChannel.write(ByteBuffer.wrap("welcome:".getBytes("utf-8"))).get();
        }
    }
}
